import React, { Component } from 'react'
import { useParams } from 'react-router-dom';
import ajax from '../../../api/ajax';
function News() {
    let params = useParams();
    console.log(params);
    let ajaxGet = async () => {
        console.log('111');
        /* url, method, params, headType */
        const url = 'http://localhost:3001/member_search';
        let result = await ajax(url, 'get', '', 'json');
        console.log(result);
    }
    let ajaxPost = async () => {
        let obj = {
            user_name: 'yanglaoban',
            password: '8888'
        }

        const url = 'http://localhost:3001/register';
        let result = await ajax(url, 'post', obj, 'form');
        console.log(result);


    }
    return (
        <div>
            <h1>news</h1>
            <button onClick={ajaxGet}>发送ajax请求 get</button>
            <button onClick={ajaxPost}>发送ajax请求post</button>
        </div>
    )
}

export default News;
/* 
组件传值
params
① 在注册路由组件时使用占位符
②在跳转路径时，进行传参
③ 获取params值，使用useParams函数进行获取，尽量在构造函数的方式中写
*/